<%@page import="com.liferay.portal.kernel.util.TextFormatter"%>
<%@page import="com.liferay.portal.model.Country"%>
<%@page import="com.liferay.portal.service.CountryServiceUtil"%>
<%@page import="com.liferay.portal.model.ListTypeConstants"%>
<%@page import="com.slayer.model.impl.LMSBookImpl"%>
<%@page import="com.liferay.portal.kernel.util.Validator"%>
<%@ include file="/html/init.jsp" %>

<%
	long bookId = ParamUtil.getLong(renderRequest, "bookId");
	LMSBook lmsBook = LMSBookLocalServiceUtil.fetchLMSBook(bookId);
	
	if (Validator.isNull(lmsBook)) {
		lmsBook = new LMSBookImpl();
	}
%>

<portlet:actionURL var="updateBookURL" name="updateBook"/>

<aui:form action="<%= updateBookURL %>">
	<aui:input name="bookId" type="hidden" bean="<%= lmsBook %>"/>
	<aui:input name="bookTitle" autoFocus="true" required="true" bean="<%= lmsBook %>"/>
	<aui:input name="author" required="true" bean="<%= lmsBook %>"/>
	
	<%@ include file="/html/address.jspf" %>

	<aui:button type="submit"/>
	<aui:button value="add-via-ajax" onClick="javascript:addThruAjax();" />
</aui:form>

<br/><a href="<portlet:renderURL/>">&laquo; Go Back</a>

<aui:script>
	function addThruAjax() {
		var frm = document.<portlet:namespace/>fm;
		
		var payload = {
			bookTitle: 	frm.<portlet:namespace/>bookTitle.value,
			author: frm.<portlet:namespace/>author.value
		};
		
		Liferay.Service(
			'/library-portlet.lmsbook/insert-book',
			payload,
			function(obj) {
				alert('id of the book inserted....' + obj.bookId);
			}
		);
	}
</aui:script>